/**
 * 
 */
package com.gr.menuw.menu.item.dialog;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.odlabs.wiquery.ui.dialog.Dialog;

import com.gr.menuw.common.StringModel;
import com.gr.menuw.menu.item.IMenuItem;


/**
 * @author Graham Rhodes 31 Dec 2010 14:31:00
 */
public class DialogMenuItem extends Panel implements IMenuItem {

    private static final long serialVersionUID = 1L;
    private final Label label;

    public DialogMenuItem(String id, String label, final Dialog dialog) {
        super(id);
        this.label = new Label("label", label);
        add(new AjaxLink<Void>("link") {

            private static final long serialVersionUID = 1L;

            @Override
            public void onClick(AjaxRequestTarget target) {
                dialog.open(target);
            }
        }.add(this.label));
    }

    /* (non-Javadoc)
     * @see com.gr.menuw.menu.item.IMenuItem#updateLabel(java.lang.String)
     */
    @Override
    public void updateLabel(String label) {
        this.label.setDefaultModel(new StringModel(label));
    }

    public void enabled(boolean enabled) {
        this.setEnabled(enabled);
    }

    /* (non-Javadoc)
     * @see com.gr.menuw.menu.item.IMenuItem#show(boolean)
     */
    @Override
    public void show(boolean visible) {
        this.setVisible(visible);
    }

}
